package com.example.demo.controller;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.example.demo.dto.ActiveUserDto;
import com.example.demo.dto.FavorableDto;
import com.example.demo.dto.TurnoverDto;
import com.example.demo.service.DataStatisticsService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Data;

@Controller
@Data
@RequestMapping("/data")
@Api("统计页面")
public class DataStatisticsController {
	@Resource
	private DataStatisticsService DataStatisticsService;
	
	@RequestMapping(value="/allData",method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation(value = "获取所有统计信息",notes = "返回所有统计信息")
	public Map<String,Object> getTurnover() {  

		Map<String,Object> map=new HashMap<String,Object>();
		//统计营业额
		BigDecimal allTurnover = DataStatisticsService.getTurnover().add(new BigDecimal(423521));
		map.put("turnover", allTurnover);
		//统计近一个月用户量
		int userNum=DataStatisticsService.getUserNumber()+175364;
		map.put("userNum", userNum);
		//统计分院个数
		int cinemaNum=DataStatisticsService.getCinema()+100;
		map.put("cinemaNum", cinemaNum);
		//统计好评率
		double favorableRate=DataStatisticsService.getFavorableRate();
		BigDecimal favorableRates=new BigDecimal(favorableRate);
		System.out.println(favorableRates.setScale(2,BigDecimal.ROUND_HALF_UP));
		map.put("favorableRates", favorableRates.setScale(2,BigDecimal.ROUND_HALF_UP));
		return map;
		
	}
	
	@RequestMapping(value="/favorableTable",method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation(value = "统计喜好",notes = "返回喜好信息")
	public List<FavorableDto> FavorableTable(){
		//统计观影喜好
		List<FavorableDto> list=DataStatisticsService.getFavorable();
		return list;
	}
	
	@RequestMapping(value="/turnoverTable",method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation(value = "获取营业额信息",notes = "返回营业额信息,需要传入一个String类型的odate字段")
	public Map<String,Object> TurnoverTable(String odata){
		Map<String,Object> map=new HashMap<String,Object>();
		//统计营业额
		List<TurnoverDto> list1=DataStatisticsService.getTurnoverTable("2018"); 
		map.put("list1", list1);
		List<TurnoverDto> list2=DataStatisticsService.getTurnoverTable("2019"); 
		map.put("list2", list2);
		return map;
	}
	
	@RequestMapping(value="/activeUserTable",method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation(value = "统计每月活跃用户",notes = "返回每月活跃用户,需要传入一个String类型的odate字段")
	public List<ActiveUserDto> ActiveUserTable(String odata){
		//统计每月活跃用户
		List<ActiveUserDto> list=DataStatisticsService.getActiveUserTable("2019"); 
		return list;
	}
	
	@RequestMapping(value="/searchTable",method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation(value = "按条件统计营业额",notes = "返回营业额,需要传入一个String类型的odate字段")
	public Map<String,Object> searchTableTable(String odata){
		Map<String,Object> map=new HashMap<String,Object>();
		//统计营业额
		List<TurnoverDto> list1=DataStatisticsService.getTurnoverTable("2019"); 
		map.put("list1", list1);
		List<TurnoverDto> list2=DataStatisticsService.getTurnoverTable(odata); 
		map.put("list2", list2);
		return map;
	}
}